package com.mxpio.erp.common;

/**
 * @Author : wpp
 * @Datetime : 2023/6/11 13:27
 * @Desc :
 * @Modor :  Modifytime:
 * @modDesc :
 */
public class LotStatusUtil {
    public static String toBinaryString(String intStr){//整数字符串转二进制，不满16位补足
        String s = Integer.toBinaryString(Integer.parseInt(intStr));
        StringBuilder append0 = new StringBuilder();
        if (s.length()<16){
            for (int i=s.length();i<16;i++){
                append0.append("0");
            }
        }
        return append0+s;
    }

    public static String switchBinaryByIndex(String binaryString,int index){//转换对应位置的char值
        if (binaryString.length()<(index+1)){//index 从左往右，从0开始
            return "-1";
        }
        StringBuilder sb = new StringBuilder(binaryString);
        char c = sb.charAt(index);
        sb.setCharAt(index, (char) (c^1));
        return sb.toString();
    }

    public static Integer switchByIndex(String binaryString,int index){//转换对应位置的char值
        if (binaryString.length()<(index+1)){
            return -1;
        }
        StringBuilder sb = new StringBuilder(binaryString);
        char c = sb.charAt(index);
        sb.setCharAt(index, (char) (c^1));
        return binaryStringToInt(sb.toString());
    }

    public static  Integer binaryStringToInt(String binaryString){//二进制字符串转int
        return Integer.parseInt(binaryString,2);
    }



    public static void main(String[] args) {
        //System.out.println(toBinaryString("343455634"));
        StringBuilder myName = new StringBuilder("domanokz");
        myName.setCharAt(4, 'x');


        String s = toBinaryString("0");
        Integer integer = switchByIndex(s, 12);
        String sss = switchBinaryByIndex(s, 0);
        System.out.println(integer);
        System.out.println(sss);
    }
}
